package com.example.ex_5;

import androidx.appcompat.app.AppCompatActivity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.Toast;

public class Main2Activity extends AppCompatActivity {
    SharedPreferences preferences;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        preferences=getSharedPreferences("count",MODE_PRIVATE);
        int count=preferences.getInt("count",0);
        Toast.makeText(this,"程序以前被使用了了"+count+"次。",1000).show();
        SharedPreferences.Editor editor=preferences.edit();
        ++count;
        editor.putInt("count", count);
        editor.commit();
    }
}
